<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#assign currentMenu="region"/>
    <#include "../common/header.ftl">
    <link rel="stylesheet" href="/js/plugins/treeview/bootstrap-treeview.css" type="text/css" />
    <script type="text/javascript" src="/js/plugins/treeview/bootstrap-treeview.js"></script>
</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-lg-3">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-lg-9">
            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-head-line">旅游区域管理</h1>
                </div>
            </div>

            <div class="row">
                <div class="col-lg-12">
                    <a role="button" class="btn btn-success">
                        <span class="glyphicon glyphicon-plus"></span> 添加区域
                    </a>
                </div>
            </div>

            <div class="row">
                <div class="col-lg-4">
                    <div id="treeview"></div>
                </div>
                <div class="col-lg-8">
                    <table class="table table-striped table-hover" style="display: none">
                        <thead>
                            <tr>
                                <th>序号</th>
                                <th>区域</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>xx</td>
                                <td>xx</td>
                                <td>
                                    <a href="javascript:" class="btn btn-info btn-xs inputBtn">
                                        <span class="glyphicon glyphicon-pencil"></span> 修改
                                    </a>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="inputModal" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">编辑</h4>
            </div>
            <div class="modal-body">
                <form id="editForm" class="form-horizontal" method="post" action="/region/saveOrUpdate.do">
                    <input type="hidden" name="id" value="" />
                    <div class="form-group">
                        <label class="col-sm-4 control-label">区域名称</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="name" placeholder="请输入区域名称">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">上级区域</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="parent.name" readonly/>
                            <input type="hidden" class="form-control" name="parent.id" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">设为推荐</label>
                        <div class="col-sm-6">
                            <select name="state" class="form-control">
                                <option value="0">普通</option>
                                <option value="1">推荐</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <a href="javascript:" class="btn btn-success submitBtn" aria-hidden="true">保存</a>
                <a href="javascript:" class="btn btn-info" data-dismiss="modal" aria-hidden="true">关闭</a>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {

        //克隆数据后还是一个jquery对象
        var td=$("table tbody tr:first").clone();
        console.log(td);

        $.get("/region/queryMenus.do",{treeview:true},function (data) {
            console.log(data);
            $("#treeview").treeview({
                color: "#428bca",
                showTags:true,  //显示"推荐"图标
                lazyLoad:function (node) {  //参数1：就是当前点击的节点
                    //发送ajax请求，获取当前节点的子节点区域
                    $.get("/region/queryMenus.do",{parentId:node.id,treeview:true},function (data) {
                        //调用treeview的addNode方法完成添加子节点
                        /*
                        treeview函数：
                        参数1：调用treeview中的哪些方法
                        参数2：该参数是一个数组
                               索引0：添加的哪些数据
                               索引1：添加到哪个节点下
                         */
                        $("#treeview").treeview("addNode",[data,node]);
                    })
                },
                onNodeSelect:function (ev,node) {    //点击当前节点触发的事件
                    $.get("/region/queryMenus.do",{parentId:node.id},function (data) {
                        console.log(data);
                        //显示右侧的数据
                        $("table").show();
                        //清除旧的数据
                        //$("table tbody").html("");
                        //再重新填充数据
                        td.appendTo($("table tbody"));
                        $.each(data,function (index,ele) {

                        })
                    })
                },
                data: [{
                    text: "全部区域",
                    nodes: data
                }]
            });
        })

    })
</script>
</body>
</html>